/*
  工资待办视图
  by zwf 20210716
 */
create view v_wage_dsh_dd
as
SELECT DISTINCT a.flag,b.dd,a.dm from bty_wage a LEFT JOIN bty_area b on a.dm=b.dm
where a.bz not like '%9%' and a.suo=99 and a.gz>0 and a.cwsh=0 and (DAY(getdate())>=11  and  DAY(getdate())<=20)
;
/*
  品牌
  by zwf 20210720
 */
create table bty_pinpai (
   id                   bigint               null,
   name                 varchar(200)         null,
   seq                  smallint             null,
   remark               varchar(1000)        null,
   create_time          datetime             null,
   update_time          datetime             null,
   create_user          bigint               null,
   update_user          bigint               null
)
/*
  门店装修 增加品牌
  by zwf 20210720
 */
ALTER TABLE [dbo].[bty_zx_mdzx] ADD [pinpai] bigint NULL
GO

IF ((SELECT COUNT(*) from fn_listextendedproperty('MS_Description',
'SCHEMA', N'dbo',
'TABLE', N'bty_zx_mdzx',
'COLUMN', N'pinpai')) > 0)
EXEC sp_updateextendedproperty @name = N'MS_Description', @value = N'品牌'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'bty_zx_mdzx'
, @level2type = 'COLUMN', @level2name = N'pinpai'
ELSE
EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'品牌'
, @level0type = 'SCHEMA', @level0name = N'dbo'
, @level1type = 'TABLE', @level1name = N'bty_zx_mdzx'
, @level2type = 'COLUMN', @level2name = N'pinpai'
GO

update bty_zx_mdzx set pinpai=1417361523710726146 where pinpai is null;


/*
  报销明细 增加品牌
  by zwf 20210721
 */
alter table bty_zx_chengben_mingxi add  pinpai bigint null;
go


/*
  科目 增加品牌
  by zwf 20210721
 */
alter table bty_zx_kemu add  pinpai bigint null;
go

/*
  科目关键字 增加品牌
  by zwf 20210721
 */
alter table bty_zx_kemu_key add  pinpai bigint null;
go

/*
  供货商报销 增加品牌
  by zwf 20210727
 */
alter table bty_zx_bx add  pinpai bigint null;
go

/*
  货品 增加品牌
  by zwf 20210727
 */
alter table bty_zx_huopin add  pinpai bigint null;
go
/*
  货品分类 增加品牌
  by zwf 20210727
 */
alter table bty_zx_huopin_fenlei add  pinpai bigint null;
go

/*
  预算模板 增加品牌
  by zwf 20210727
 */
alter table bty_zx_yusuan_temp add  pinpai bigint null;
go



DROP view v_wsjd_wm;
CREATE view v_wsjd_wm
AS
SELECT a.gcg_wsjd_id,a.mingcheng,a.yaoma,a.yyjl,b.takeaway_statusM,
(case
    when b.takeaway_statusM ='1' then a.mingcheng
    else ''
end) mtmingcheng,
b.takeaway_statusE,
(case
    when b.takeaway_statusE ='1' then a.mingcheng
    else ''
end) elememingcheng
 from gcg_wsjd a INNER JOIN gcg_wsjd_shenpi b on a.gcg_wsjd_id=b.gcg_wsjd_id and b.type=3
;

CREATE view v_md_archives
as
SELECT d.bh code,d.yaoma,d.dm,b.bh,b.xm from bty_archives b
INNER JOIN bty_brand d on b.dm=d.dudao